package com.apes.framework.plugin.workflow.domain;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.frame.model.Branch;
import com.apes.scm.rbac.model.User;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：ProcessInstance扩展
 *
 * @author xul
 * @create 2018-07-27 9:48
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ProcessInstanceExt.CONST_TABLE_NAME, indexes = {
        @Index(name = "wf_Process_instance_id", columnList = "process_instance_id"),
        @Index(name = "wf_Process_business", columnList = "business_type, business_key")})
public class ProcessInstanceExt extends BaseModel {
    public static final String CONST_TABLE_NAME = "wf_Process_Instance_ext";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "流程实例扩展")
    private long id;

    @Column(name = "process_instance_id", length = 32)
    private String processInstanceId; //流程实例编号

    @Column(name = "business_type", length = 32)
    private String businessType; //单据类型

    @Column(name = "business_key", length = 32)
    private String businessKey; //单据ID

    @Comment("流程发起人")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "process_initiator", referencedColumnName = "id")
    private User processInitiator;


    @Comment("流程发起部门")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "process_initiating_department", referencedColumnName = "id")
    private Branch processInitiatingDepartment;
}
